#include "BlockQueue.hpp"

void* Producer(void* arg)
{
    auto queue = static_cast<BlockQueue<int>*>(arg);

    int count=0;

    while(1)
    {
        sleep(1);
        queue->push(count++);
        std::cout<<"Produced: " << count << std::endl;
    }

    return nullptr;
}

void* Consumer(void* arg)
{
    auto queue = static_cast<BlockQueue<int>*>(arg);
    while(1)
    {
        int value = queue->pop();
        usleep(10);
        std::cout << "Consumed: " << value << std::endl;
    }
    return nullptr;
}

int main()
{
    auto queue =new BlockQueue<int>();
    pthread_t producer, consumer;
    pthread_create(&producer, nullptr, Producer,queue);
    pthread_create(&consumer, nullptr, Consumer, queue);

    pthread_join(producer, nullptr);
    pthread_join(consumer, nullptr);

    delete queue;
    return 0;
}